//
//  PaymentStasticCell.m
//  PropertyMananger
//
//  Created by bh on 17/3/7.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "PaymentStasticCell.h"

#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI) * 360

@implementation PaymentStasticCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * CellID = @"LeaderFormCellID";
    PaymentStasticCell * cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (!cell) {
        
        cell = [[PaymentStasticCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        UILabel * tipLabel = [[UILabel alloc]init];
        [self.contentView addSubview:tipLabel];
        tipLabel.backgroundColor = BHColor(245, 95, 29);
        
        [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView).with.offset(15);
            make.top.equalTo(self.contentView).with.offset(15);
            make.size.mas_equalTo(CGSizeMake(2, 15));
        }];
        
        self.progressLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.progressLabel];
        self.progressLabel.text = @"本月工单进度";
        
        self.progressLabel.textAlignment = NSTextAlignmentLeft;
        self.progressLabel.font = BHFont(18);
        self.progressLabel.textColor = [UIColor blackColor];
        
        
        [self.progressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(tipLabel.mas_trailing).with.offset(5);
            make.centerY.equalTo(tipLabel).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(150, 25));
        }];
        
        //        self.detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        //        [self.contentView addSubview:self.detailBtn];
        //
        //        [self.detailBtn setTitle:@"明细 >>" forState:UIControlStateNormal];
        //        [self.detailBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //        self.detailBtn.titleLabel.font = BHFont(15);
        //
        //        [self.detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        //            make.trailing.equalTo(self.contentView).with.offset(-15);
        //            make.centerY.equalTo(tipLabel).with.offset(0);
        //            make.size.mas_equalTo(CGSizeMake(70, 30));
        //        }];
        
        self.monthButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.monthButton];
        [self.monthButton setImage:IMG(@"ico_statistics_month") forState:UIControlStateNormal];
        
        [self.monthButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self.contentView).with.offset(-15);
            make.centerY.equalTo(tipLabel).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
        
        self.yearLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.yearLabel];
        
        self.yearLabel.textAlignment = NSTextAlignmentRight;
        self.yearLabel.textColor = BHColor(102, 102, 102);
        self.yearLabel.font = BHFont(15);
        self.yearLabel.text = @"2017年/1月份";
        
        [self.yearLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self.monthButton.mas_leading).with.offset(0);
            make.centerY.equalTo(self.monthButton).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(BHscreenW/3+10, 25));
        }];
        
        
        [self setupCircleView];
        
        [self createProgressFormUI];
        
         [self createButton];
    }
    
    return self;
}
/**
 *  初始化圆形视图
 */
- (void)setupCircleView{
    
    //1.初始化

//    self.currentNum = 200;
//    self.totalNum = 600;
    self.circleView = [[FZHDrawCircleView alloc]init];
    [self.contentView addSubview:self.circleView];
    
    [self.circleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView).with.offset(BHscreenW/2 - 80);
        make.top.equalTo(self.monthButton.mas_bottom).with.offset(110);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    
    //2.彩色属性
    self.circleView.colourFillColor = BHColor(65, 221, 195);//颜色
    self.circleView.normalFillColor = BHColor(221, 233, 244);
    self.circleView.colourStartAngle = 0;//起始点
   self.circleView.colourEndAngle = DEGREES_TO_RADIANS(self.currentNum/self.totalNum);
    
    
    self.circleViewTwo = [[FZHDrawCircleView alloc]init];
    [self.contentView addSubview:self.circleViewTwo];

    
    [self.circleViewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.contentView).with.offset(20);
        make.top.equalTo(self.circleView).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    
    
    //2.彩色属性
    self.circleViewTwo.colourFillColor = BHColor(255, 200, 68);//颜色
    self.circleViewTwo.normalFillColor = BHColor(221, 233, 244);
    self.circleViewTwo.colourStartAngle = 0;//起始点
    self.circleViewTwo.colourEndAngle = DEGREES_TO_RADIANS(self.currentNum/self.totalNum);
    
    self.circleView.cateLabel.text = @"0.00";
    
    self.circleViewTwo.cateLabel.text = @"0.00";
}

- (void)createProgressFormUI{
    
    UILabel * cubeLabel = [[UILabel alloc]init];
    [self.contentView addSubview:cubeLabel];
    cubeLabel.backgroundColor = BHColor(221, 233, 244);
    
    [cubeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView).with.offset(25);
        make.top.equalTo(self.circleView).with.offset(50);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];
    
    self.finishLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.finishLabel];
    
    self.finishLabel.text = @"未完成:40单 25%";
    self.finishLabel.font = BHFont(13);
    self.finishLabel.textColor = BHColor(102, 102, 102);
    
    [self.finishLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(cubeLabel.mas_trailing).with.offset(5);
        make.centerY.equalTo(cubeLabel).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 25));
    }];
    
    UIView * lineView = [[UIView alloc]init];
    [self.contentView addSubview:lineView];
    lineView.backgroundColor = BHGrayColor;
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.finishLabel).with.offset(0);
        make.top.equalTo(self.finishLabel.mas_bottom).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(110, 1));
    }];
    
    
    UILabel * cubeLabel1 = [[UILabel alloc]init];
    [self.contentView addSubview:cubeLabel1];
    cubeLabel1.backgroundColor = BHColor(65, 221, 195);
    
    [cubeLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(cubeLabel).with.offset(0);
        make.top.equalTo(lineView).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];
    
    
    self.unFinishLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.unFinishLabel];
    
    self.unFinishLabel.text = @"已完成:140单 75%";
    self.unFinishLabel.font = BHFont(13);
    self.unFinishLabel.textColor = BHColor(102, 102, 102);
    
    [self.unFinishLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(cubeLabel1.mas_trailing).with.offset(5);
        make.centerY.equalTo(cubeLabel1).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 25));
    }];
    
    
}
- (void)createButton{
    
    self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.leftButton];
    //   self.leftButton.backgroundColor =[UIColor redColor];
    
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(self.contentView).offset(0);
        make.top.equalTo(self.progressLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 200));
    }];
    
    self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.rightButton];
    //    self.rightButton.backgroundColor =[UIColor redColor];
    
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.trailing.equalTo(self.contentView).offset(0);
        make.top.equalTo(self.progressLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 200));
    }];
    
}

- (void)setModel:(LeaderModel *)model{

     _model = model;

    if ([model.UnReceivedCost isEqualToString:model.WuYueFeeTotalCost]) {
        
        self.circleView.colourEndAngle = DEGREES_TO_RADIANS(0.001/600.0);
    }else if ([model.ReceivedCost isEqualToString:model.WuYueFeeTotalCost]){
        
        self.circleView.colourEndAngle = DEGREES_TO_RADIANS(model.WuYueFeeTotalCost.floatValue/model.WuYueFeeTotalCost.floatValue);
    }else{
        
        self.circleView.colourEndAngle = DEGREES_TO_RADIANS(model.ReceivedCost.floatValue/model.WuYueFeeTotalCost.floatValue);
    }

    if ([model.PakingTotalFee isKindOfClass:[NSNull class]] || [model.PakingTotalFee isEqualToString:@""]) {
        
        self.circleViewTwo.cateLabel.text = @"0.00";
        self.circleViewTwo.colourEndAngle = DEGREES_TO_RADIANS(0.001/600.0);
        
    }else{
        self.circleViewTwo.colourEndAngle = DEGREES_TO_RADIANS(model.PakingTotalFee.floatValue/model.PakingTotalFee.floatValue);
    }

    
    if (![model.allroomCount isEqualToString:@""]) {
    
        NSString * unFinishPersent  = [NSString stringWithFormat:@"%.f%%",(model.notroomCount.floatValue/model.allroomCount.floatValue)*100];
        NSString * finishPersent = [NSString stringWithFormat:@"%.f%%",(model.okroomCount.floatValue/model.allroomCount.floatValue)*100];
        
        self.finishLabel.text = [NSString stringWithFormat:@"未交费:%@户 %@",model.notroomCount,unFinishPersent];
        self.unFinishLabel.text = [NSString stringWithFormat:@"已缴费:%@户 %@",model.okroomCount,finishPersent];
    
        DLog(@"未缴费的户数: == %@",model.notroomCount);
        
         self.circleView.cateLabel.text = model.WuYueFeeTotalCost;
    
    
    }else{
    
        NSString * unFinishPersent  = @"0%";
        NSString * finishPersent = @"0%";
        
        self.finishLabel.text = [NSString stringWithFormat:@"未交费:%@户 %@",@"0",unFinishPersent];
        self.unFinishLabel.text = [NSString stringWithFormat:@"已缴费:%@户 %@",@"0",finishPersent];
        
        self.circleView.cateLabel.text = @"0.00";
      
    }
    
    if ([model.WuYueFeeTotalCost isEqualToString:@""]) {
        
         self.circleView.cateLabel.text = @"0.00";
    }
    
    if (![model.PakingTotalFee isEqualToString:@""]) {
        
          self.circleViewTwo.cateLabel.text = model.PakingTotalFee;
    }else{
    
         self.circleViewTwo.cateLabel.text = @"0.00";
    }

    self.progressLabel.text  = @"本月缴费统计";
    //4.文字
    self.circleView.moneyNumLabel.text = @"物业缴费";
    self.circleViewTwo.moneyNumLabel.text = @"停车费入账";
    
    
    [self.circleView setNeedsDisplay];
    
    [self.circleViewTwo setNeedsDisplay];

}

@end
